package com.msb.order.factory;

import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.msb.order.service.UserFeignService;
import com.msb.order.util.Result;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class FallbackOrderFeignServiceFactory implements FallbackFactory<UserFeignService> {
    @Override
    public UserFeignService create(Throwable throwable) {
        return new UserFeignService() {
            @Override
            public Result getUserName(Integer userId) {
                if (throwable instanceof FlowException) {
                    return Result.error(100,"接口限流了");
                }

                return Result.error(-1,"=======服务降级了========");
            }
        };
    }
}